﻿using Sasc.PV.BLL;
using Sasc.PV.BLL.ZhuDing;
using Sasc.PV.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Sasc.PV.Web.Admin.Zhuding
{
    public partial class PenTuAdd : PVGongXuAdminPage<ZhuDingCheJianManagement,ZhuDingPenTuGongXu,ZhuDingGongXuTarget>
    {
        #region Page Load
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!HasPermission(GongXuQuanXianLeiXing.ADD))
                MessageBox.ShowAndRedirect(this, "对不起，没有权限访问该页面。", "PenTu");
            if (!IsPostBack)
            {
                PenTuDateTimeTextBox.Text = DateTime.Now.Format();
            }
        }
        #endregion

        #region GetQuanXianValue
        protected override string GetQuanXianValue()
        {
            return "101";
        }
        #endregion 

        #region Submit Button
        protected void SubmitImageButton_Click(object sender, ImageClickEventArgs e)
        {
            var reason = string.Empty;

            decimal parseDecimal = 0;
            DateTime parseDateTime = DateTime.Now;

            var model = new PvZDPenTu
            {
                CreatedBy = LoginUserName,
                CreatedDate = DateTime.Now,
                FanGongVersion = 0,
                DanHuaGuiAmount = decimal.TryParse(DanHuaGuiAmountTextBox.Text, out parseDecimal) ? parseDecimal : 0,
                DanHuaGuiPiCi = DanHuaGuiPiCiTextBox.Text,
                DanHuaGuiPinPai = DanHuaGuiPinPaiTextBox.Text,
                FuChaUser = FuChaUserTextBox.Text,
                GanGuoBianHao = GanGuoBianHaoTextBox.Text,
                GanGuoPiCi = GanGuoPiCiTextBox.Text,
                GanGuoPinPai = GanGuoPinPaiTextBox.Text,
                GanGuoXingHao = GanGuoXingHaoTextBox.Text,
                //GongXuRecID ="",
                GuiRongJiaoAmount = decimal.TryParse(GuiRongJiaoAmountTextBox.Text, out parseDecimal) ? parseDecimal : 0,
                GuiRongJiaoPiCi = GuiRongJiaoPiCiTextBox.Text,
                GuiRongJiaoPinPai = GuiRongJiaoPinPaiTextBox.Text,
                JianChaNote = JianChaNoteTextBox.Text,
                LastUpdatedBy = LoginUserName,
                LastUpdatedDate = DateTime.Now,
                PenTuDateTime = DateTime.TryParse(PenTuDateTimeTextBox.Text, out parseDateTime) ? parseDateTime : DateTime.Now,
                PenTuMaxTemp = decimal.TryParse(PenTuMaxTempTextBox.Text, out parseDecimal) ? parseDecimal : 0,
                PenTuMinTemp = decimal.TryParse(PenTuMinTempTextBox.Text, out parseDecimal) ? parseDecimal : 0,
                WaterAmount = decimal.TryParse(WaterAmountTextBox.Text, out parseDecimal) ? parseDecimal : 0
            };

            var target = model.CreateTarget();

            if (CheJianGongXu.CanProcess(model, target, out reason))
            {
                CheJianGongXu.AddGongXuRec(model, target);

                MessageBox.ShowAndRedirect(this, "《喷涂工序卡》创建成功！", "PenTu");
            }
            else
            {
                MessageBox.Show(this, reason);
            }
        }
        #endregion
    }
}